const models = require('./../../db/mysqldb/index')
const { SuccessModel, ErrorModel } = require('./../../utils/index')
const config = require('./../../config/index')
const { AdminSystemLog } = require('./adminSystemLog')
const Op = require('sequelize/index').Op
const logger = require('../../utils/logger')
class UserRole {
  /**
   * 用户角色创建
   * @param {string} user_role_name 
   * @param {string} user_role_description 
   * @param {string} user_role_icon 
   * @param {string} user_role_type 
   * @param {string} is_show 
   * @param {string} enable 
   */
  static async createUserRole (req, res) {
    const { user_role_name,
      user_role_description,
      user_role_icon,
      user_role_type,
      is_show,
      enable } = req.body
    logger.info('createUserRole', 'req.body', req.body)
    try {
      let oneUserRole = await models.user_role.findOne({
        where: {
          user_role_name
        }
      })
      logger.info('createUserRole', 'oneUserRole', oneUserRole)
      if (oneUserRole) {
        res.json(new ErrorModel('用户角色名已存在'))
      }
      const create_res = models.user_role.create({
        user_role_name,
        user_role_description,
        user_role_icon,
        user_role_type,
        is_show,
        enable
      })
      logger.info('createUserRole', 'create_res', create_res)
      const system_log_res = models.system_log.create({
        uid,
        type: 3,
        content: `成功创建了‘${reqData.user_role_name}’用户角色`
      })
      logger.info('createUserRole', 'system_log_res', system_log_res)
    } catch (error) {
      res.json(new ErrorModel([], error.message))
    }
  }


}
module.exports = {
  UserRole
}